package activity

import (
	act "lao-a/models/activity"
	"lao-a/models/model"
	"net/http"
	"net/url"
	"time"
)

// ActivityMemList 查询活动报名列表
func (c *ActivityController) ActivityMemList() {
	params := url.Values{}
	params.Set("ActivityId", c.GetString(":actId"))

	acts, err := c.dao.GetActivityMemList(params)

	if err != nil {
		c.ResponseJson(err, http.StatusInternalServerError)
	}

	c.ResponseJson(map[string]interface{}{
		"ActivityMembers": acts,
	})
}

// GetActivityMember 查询活动报名详情
func (c *ActivityController) GetActivityMember() {
	applyId, _ := c.GetInt(":applyId")
	actDetail, err := c.dao.GetActivityMemByID(applyId)

	if err != nil {
		c.ResponseJson(err, http.StatusInternalServerError)
	}

	c.ResponseJson(map[string]interface{}{
		"ActivityMember": actDetail,
	})
}

// UpdateActivityStatus
func (c *ActivityController) UpdateActivityStatus() {
	actDetail := model.TaActivityMember{}
	actDetail.ApplyId, _ = c.GetInt(":applyId")
	actDetail.Status, _ = c.GetInt(":sts")

	if err := c.dao.UpdateActivityMemStatus(&actDetail); err != nil {
		c.ResponseJson(err, http.StatusInternalServerError)
	}

	c.ResponseJson("ok")
}

// UpdateActivityMemID
func (c *ActivityController) UpdateActivityMemID() {
	actDetail := model.TaActivityMember{}
	actDetail.ApplyId, _ = c.GetInt(":applyId")
	actDetail.MemId, _ = c.GetInt(":memId")

	if err := c.dao.UpdateActivityMemID(&actDetail); err != nil {
		c.ResponseJson(err, http.StatusInternalServerError)
	}

	c.ResponseJson("ok")
}

// SaveActivityMember 保存活动报名
func (c *ActivityController) SaveActivityMember() {
	actDetail := &model.TaActivityMember{}
	actDetail.ActivityId, _ = c.GetInt(":actId")
	actDetail.ApplyDate = time.Now()
	actDetail.UserName = c.GetString("UserName")
	actDetail.Phone = c.GetString("Phone")
	actDetail.Remark = c.GetString("Remark")
	actDetail.Status = act.ACTIVITY_APPLY_READY

	var err error
	actDetail, err = c.dao.SaveActivityMember(actDetail)
	if err != nil {
		c.ResponseJson(err, http.StatusInternalServerError)
	}

	c.ResponseJson(map[string]interface{}{
		"ActivityMember": actDetail,
	})
}
